/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipo.mm.ejb.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author makcro
 */
@Entity
@Table(name = "MEETING")
@NamedQueries({@NamedQuery(name = "Meeting.findAll", query = "SELECT DISTINCT m FROM Meeting m LEFT JOIN FETCH m.documentCollection WHERE m.deleted = false"),
    @NamedQuery(name = "Meeting.findById", query = "SELECT m FROM Meeting m WHERE m.id = :id"),
    //finding meeting by id, regardless of attached documents so using left join fetch
    @NamedQuery(name = "Meeting.findByIdFetchDocs", query = "SELECT DISTINCT m FROM Meeting m LEFT JOIN FETCH m.documentCollection WHERE m.id = :id"),
    @NamedQuery(name = "Meeting.findByEventName", query = "SELECT m FROM Meeting m WHERE m.eventName = :eventName"),
    @NamedQuery(name = "Meeting.findByDate", query = "SELECT m FROM Meeting m WHERE m.date = :date"),
    @NamedQuery(name = "Meeting.findByVenue", query = "SELECT m FROM Meeting m WHERE m.venue = :venue"),
    @NamedQuery(name = "Meeting.findByConclusion", query = "SELECT m FROM Meeting m WHERE m.conclusion = :conclusion"),
    @NamedQuery(name = "Meeting.findByNote", query = "SELECT m FROM Meeting m WHERE m.note = :note"),
    @NamedQuery(name = "Meeting.findByDeleted", query = "SELECT m FROM Meeting m WHERE m.deleted = :deleted"),
    @NamedQuery(name = "Meeting.markDeleted", query = "UPDATE Meeting m SET m.deleted = true WHERE m.id = :id_param")
})
public class Meeting implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Column(name = "EventName")
    private String eventName;
    @Basic(optional = false)
    @Column(name = "Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Column(name = "StartTime")
    private String startTime;
    @Column(name = "EndTime")
    private String endTime;
    @Column(name = "Venue")
    private String venue;
    @Column(name = "Conclusion")
    private String conclusion;
    @Column(name = "Note")
    private String note;
    @Basic(optional = false)
    @Column(name = "Deleted")
    private boolean deleted;
    
    @Basic(optional = false)
    @Column(name = "Draft")
    private boolean draft;
    @JoinTable(name = "REPRESENTATIVE_MEETING_JOIN", joinColumns = {@JoinColumn(name = "Meeting", referencedColumnName = "ID")}, inverseJoinColumns = {@JoinColumn(name = "Representative", referencedColumnName = "ID")})
    @ManyToMany(fetch=FetchType.EAGER)
    private List<Representative> representativeCollection;
    @JoinColumn(name = "User", referencedColumnName = "Username")
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "Organizer", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Representative organizer;
   @OneToMany(cascade = CascadeType.ALL, mappedBy = "meeting")
    private List<Document> documentCollection;

    @OneToMany(mappedBy="meetingId", fetch=FetchType.EAGER,cascade=CascadeType.ALL)
    private ArrayList<Actions> meetingActions;

    public Meeting() {
    }

    public Meeting(Integer id) {
        this.id = id;
    }

    public Meeting(Integer id, Date date, boolean deleted) {
        this.id = id;
        this.date = date;
        this.deleted = deleted;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getVenue() {
        return venue;
    }

    public void setVenue(String venue) {
        this.venue = venue;
    }

    public String getConclusion() {
        return conclusion;
    }

    public void setConclusion(String conclusion) {
        this.conclusion = conclusion;
    }

    public String getNote() {
        return note;
    }

    

    public void setNote(String note) {
        this.note = note;
    }

    public boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public boolean getDraft() {
        return draft;
    }

    public void setDraft(boolean draft) {
        this.draft = draft;
    }


    public List<Representative> getRepresentativeCollection() {
        return representativeCollection;
    }

    public void setRepresentativeCollection(List<Representative> representativeCollection) {
        this.representativeCollection = representativeCollection;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Representative getOrganizer() {
        return organizer;
    }

    public void setOrganizer(Representative organizer) {
        this.organizer = organizer;
    }

    public List<Document> getDocumentCollection() {
        return documentCollection;
    }

    public void setDocumentCollection(List<Document> documentCollection) {
        this.documentCollection = documentCollection;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public ArrayList<Actions> getMeetingActions() {
        return meetingActions;
    }

    public void setMeetingActions(ArrayList<Actions> meetingActions) {


        this.meetingActions = meetingActions;
    }

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Meeting)) {
            return false;
        }
        Meeting other = (Meeting) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.ipo.mm.ejb.entities.Meeting[id=" + id + "]";
    }
}
